/*
 * @Author: xushuhao
 * @Email: xshmouse@163.com
 * @Date: 2020-04-18 09:57:15
 * @Last Modified by: xushuhao
 * @Last Modified time: 2020-06-12 11:10:28
 * @Description: 简易路由表，支持args参数对象传递。不支持切换动画，不支持复杂功能。 
 * 需要其它路由功能参考RouteTransition类方法。
 * 
 * 无参数调用方式： Navigator.pushNamed(context, '/demo_sf_symbols');  
 * 含参数调用方式： G.pushNamed('routeName', {'arg1': 123});   需继承基类   
 */


import 'package:flutter/material.dart';
import 'package:flutter_code_framework/base/base_main_tabbar.dart';
import 'package:flutter_code_framework/demo/demo_iosvideo.dart';
import 'package:flutter_code_framework/demo/demo_video.dart';

import 'package:flutter_code_framework/pages/class_room_page.dart';
import 'package:flutter_code_framework/pages/common/search.dart';
import 'package:flutter_code_framework/pages/lessons_page.dart';
import 'package:flutter_code_framework/pages/my_page.dart';
import 'package:flutter_code_framework/pages/resources_page.dart';
import 'package:flutter_code_framework/pages/startup_page.dart';


import 'package:flutter_code_framework/pages/login.dart';
import 'package:flutter_code_framework/pages/user_guide.dart';
import 'package:flutter_code_framework/pages/class/class_info_page.dart';
import 'package:flutter_code_framework/pages/lesson_publish.dart';
import 'package:flutter_code_framework/demo/demo_image.dart';
class Router {
  static final _routes = {    
    // 业务页面
    '/startup_page': (BuildContext context, { Object args }) => StartupPage(),
    '/main_page': (BuildContext context, { Object args }) => BaseMainTabbarPage(),
    '/lessons_page': (BuildContext context, { Object args }) => LessonsPage(),
    '/classroom_page': (BuildContext context, { Object args }) => ClassroomPage(),
    '/classinfo_page': (BuildContext context, { Object args }) => ClassInfoPage(),
    '/resources_page': (BuildContext context, { Object args }) => ResourcesPage(),
    '/my_page': (BuildContext context, { Object args }) => MyPage(),
    '/login' :(BuildContext context, { Object args }) => Login(),
    '/user_guide':(BuildContext context, { Object args }) => UserGuide(),
     '/search':(BuildContext context, { Object args }) => Search(),
     '/lesson_publish':(BuildContext context, { Object args}) => LessonPublish(),
     '/demo_image':(BuildContext context, { Object args}) => ImageDemo(),
     '/demo_iosvideo':(BuildContext context, { Object args}) =>DemoIosVideo (),
     '/demo_video':(BuildContext context, { Object args}) =>DemoVideo (),
    // 组件列表
    
  };

  static Router _singleton;

  Router._internal();

  factory Router() {
    if(_singleton == null) {
      _singleton = Router._internal();
    }

    return _singleton;
  }

  /// 监听route
  Route getRoutes(RouteSettings settings) {
    String routeName = settings.name;
    final Function builder = Router._routes[routeName];

    print(settings);

    if(builder == null) {
      return null;
    } else {
      return MaterialPageRoute(
        settings: settings, 
        builder: (BuildContext context) => builder(context, args: settings.arguments)
      );
    }
  }

  Widget getRoutesWidget(BuildContext context, RouteSettings settings) {
    String routeName = settings.name;
    
    print(settings);

    final Function builder = Router._routes[routeName];
    if(builder == null) {
      return null;
    } else {
      return builder(context, args: settings.arguments);
    }
  }
}
